package com.hgy.crowd.constant;

import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author He
 * @Date 2020/7/2 20:53
 */
public class AccessPassResource {
    /**
     * 不进行登录拦截的网页请求
     */
    public static Set<String> passResource=new HashSet<>();
    static {
        passResource.add("/");
        passResource.add("/auth/member/to/reg/page");
        passResource.add("/auth/member/to/login/page");
        passResource.add("/auth/member/send/short/message.json");
        passResource.add("/auth/do/member/register");
        passResource.add("/auth/member/do/login");
        passResource.add("/auth/member/logout");
    }

    /**
     * 静态资源路径
     */
    public static Set<String> staticPassResource=new HashSet<>();
    static {
        staticPassResource.add("bootstrap");
        staticPassResource.add("css");
        staticPassResource.add("fonts");
        staticPassResource.add("img");
        staticPassResource.add("jquery");
        staticPassResource.add("layer");
        staticPassResource.add("script");
        staticPassResource.add("ztree");
    }

    /**
     * 判断请求路径是否为静态资源，如果是则返回true
     * @param request
     * @return
     */
    public static boolean judgeRequestPathWhetherStaticResource(HttpServletRequest request){
        String servletPath = request.getServletPath();
        if (servletPath==null||servletPath.length()==0){
            throw new RuntimeException("请求路径有误");
        }
        String[] split = servletPath.split("/");
        return staticPassResource.contains(split[1]);
    }
}
